<template>
  <a-modal
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    :title="model.businessFlag"
    :visible="visible"
    :width="1200"
    cancelText="关闭"
    @cancel="handleCancel"
    @ok="handleOk">
    <template slot="footer">
      <a-button @click="handleCancel">取消</a-button>
      <a-button v-if="title=='审批'" :loading="confirmLoading" type="primary" @click="handleOk(4)">
        驳回
      </a-button>
      <a-button v-if="title=='审批'" :loading="confirmLoading" type="primary" @click="handleOk(3)">
        通过
      </a-button>
    </template>
    <a-spin :spinning="confirmLoading">
      <a-row :gutter="24">
        <a-col v-if="title == '审批'&&model.businessFlag=='门店修改'" :md="bigmd" :sm="24">
          <a-form :form="form1">
            <a-row :gutter="24">
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="门店名称"
                >
                  <a-input v-model="oldModel.terminalName" :disabled="disableSubmit"
                           placeholder="请输入门店名称"/>
                </a-form-item>
              </a-col>
              <!--          详细地址-->
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="详细地址"
                >
                  <a-input v-model="oldModel.address" :disabled="disableSubmit"
                           placeholder="请输入地址"/>
                </a-form-item>
              </a-col>
              <!--          营业执照-->
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="营业执照代码">
                  <a-input v-model="oldModel.businessLicense" :disabled="disableSubmit"
                           placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <!--          行政区域-->
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="行政区域"
                >
                  <j-area-linkage v-model="oldModel.areaLinkage" :area.sync="form.area" :city.sync="form.city"
                                  :disabled="disableSubmit"
                                  :province.sync="form.province" type="cascader" @change="handlePca"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="烟草许可证号">
                  <a-input v-model="oldModel.smokeLicenceNum" :disabled="disableSubmit"
                           placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="烟草许可证有效期">
                  <a-range-picker v-model="oldModel.smokeLicenceDate"
                                  :disabled="disableSubmit" format="YYYY-MM-DD"
                                  style="width: 100%;" valueFormat="YYYY-MM-DD"></a-range-picker>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="门店类型"
                >
                  <cn-dict-select-tag v-model="oldModel.terminalType"
                                      :disabled="disableSubmit"
                                      :options="{value:'dictDataCode',label:'dictDataDesc'}" :triggerChange="true"
                                      dictCode="terminal_type" placeholder="请选择门店类型"/>
                </a-form-item>
              </a-col>
              <!--门店等级-->
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="门店等级"
                >
                  <cn-dict-select-tag v-model="oldModel.terminalLevel"
                                      :disabled="disableSubmit"
                                      :options="{value:'dictDataCode',label:'dictDataDesc'}" :triggerChange="true"
                                      dictCode="terminal_level" placeholder="请选择门店级别"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="所属组织"
                >
                  <j-tree-select
                    ref="selectRef"
                    v-model="oldModel.orgCode"
                    :disabled="disableSubmit"
                    data-type="org"
                    placeholder="选择组织"
                    @change="handleDepartCode"
                  />
                </a-form-item>
              </a-col>

              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="是否总店"
                >
                  <a-select
                    :disabled="disableSubmit"
                    v-model="oldModel.headOfficeStr"
                    placeholder="请选择"
                  >
                    <a-select-option value="是">
                      是
                    </a-select-option>
                    <a-select-option value="否">
                      否
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="面积"
                >
                  <a-input v-model="oldModel.acreage" :disabled="disableSubmit" placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="营业时间">
                  <a-time-picker v-model="oldModel.businessStartDate" :disabled="disableSubmit" format="HH:mm"
                                 valueFormat="HH:mm"/>
                  <span> ~ </span>
                  <a-time-picker v-model="oldModel.businessEndDate" :disabled="disableSubmit" format="HH:mm"
                                 valueFormat="HH:mm"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="店员数量"
                >
                  <a-input v-model="oldModel.clerkNum" :disabled="disableSubmit" placeholder="请输入"
                           style="width: 378px"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="烟草许可证">
                  <j-image-upload :value="[oldModel.retailLicenceImg]"
                                  :disabled="disableSubmit" class="avatar-uploader"
                                  text="上传"></j-image-upload>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="门头照">
                  <j-image-upload :disabled="disableSubmit" class="avatar-uploader" text="上传"
                                  :value="[oldModel.avatar]"></j-image-upload>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="陈列照">
                  <j-upload :value="oldModel.disPlayImgList" :disabled="disableSubmit"
                            :number="3"
                            :returnUrl="false"
                            accept=".png,.jpg,.jpeg" class="avatar-uploader"
                            fileType="image"
                            text="3张内"
                  ></j-upload>
                </a-form-item>
                <!--            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="陈列照">-->
                <!--              <j-image-upload v-decorator="[ 'disPlayImgList',validatorRules.disPlayImgList]" :disabled="disableSubmit" class="avatar-uploader"-->
                <!--                              text="上传"></j-image-upload>-->
                <!--            </a-form-item>-->
              </a-col>
              <!--          联系人-->
              <a-divider orientation="left" style="font-weight: 600;margin-top: 100px;">联系人电话</a-divider>
              <div v-for="(item,index) in oldModel.extendVos" key="index">
                <a-form-model :label-col="labelCol" :rules="rules" :wrapper-col="wrapperCol">
                  <a-col :md="md==12?8:md" :sm="24">
                    <a-form-model-item
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      label="联系人"
                      prop="contacts"
                    >
                      <a-input v-model="item.contacts" :disabled="disableSubmit" placeholder="请输入联系人"/>
                    </a-form-model-item>
                  </a-col>
                  <!--          联系电话-->
                  <a-col :md="md==12?8:md" :sm="24">
                    <a-form-model-item
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      label="联系电话"
                      prop="telephone"
                    >
                      <a-input v-model="item.telephone"
                               :disabled="disableSubmit" placeholder="请输入联系电话"/>
                    </a-form-model-item>
                  </a-col>
                  <a-col :md="md==12?8:md" :sm="24">
                    <a-form-model-item
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      label="是否主号"
                      prop="isMainStr"
                    >
                      <a-select
                        v-model="item.isMainStr"
                        :disabled="disableSubmit"
                        placeholder="请选择"
                      >
                        <a-select-option value="是">
                          是
                        </a-select-option>
                        <a-select-option value="否">
                          否
                        </a-select-option>
                      </a-select>
                    </a-form-model-item>
                  </a-col>
                </a-form-model>
                <a-button v-if="!disableSubmit" style="position: relative;right: -1150px;top: -38px;" type="primary"
                          @click="clickToadd($event,index)">{{ index == 0 ? '+' : '-' }}
                </a-button>
              </div>
            </a-row>
          </a-form>
        </a-col>
        <a-col :md="bigmd" :sm="24">
          <a-form :form="form">
            <a-row :gutter="24">
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="门店名称"
                >
                  <a-input v-decorator="['terminalName', validatorRules.terminalName]" :disabled="disableSubmit"
                           placeholder="请输入门店名称" :style="model.terminalName!=oldModel.terminalName&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"/>
                </a-form-item>
              </a-col>
              <!--          详细地址-->
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="详细地址"
                >
                  <a-input v-decorator="['address', validatorRules.address]" :disabled="disableSubmit"
                           placeholder="请输入地址" :style="model.address!=oldModel.address&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"/>
                </a-form-item>
              </a-col>
              <!--          营业执照-->
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="营业执照代码">
                  <a-input v-decorator="['businessLicense', validatorRules.businessLicense]" :disabled="disableSubmit"
                           placeholder="请输入" :style="model.businessLicense!=oldModel.businessLicense&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"/>
                </a-form-item>
              </a-col>
              <!--          行政区域-->
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="行政区域"
                >
                  <j-area-linkage v-model="areaLinkage" :area.sync="form.area" :city.sync="form.city"
                                  :disabled="disableSubmit"
                                  :province.sync="form.province" type="cascader" @change="handlePca"
                                  :style="areaLinkage!=oldModel.areaLinkage&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"
                                  />
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="烟草许可证号">
                  <a-input v-decorator="[ 'smokeLicenceNum',validatorRules.smokeLicenceNum]" :disabled="disableSubmit"
                           placeholder="请输入" :style="model.smokeLicenceNum!=oldModel.smokeLicenceNum&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="烟草许可证有效期">
                  <a-range-picker v-decorator="['smokeLicenceDate',validatorRules.smokeLicenceDate]"
                                  :disabled="disableSubmit" format="YYYY-MM-DD"
                                  style="width: 100%;" valueFormat="YYYY-MM-DD"
                                  :style="model.smokeLicenceDate!=oldModel.smokeLicenceDate&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"
                                  ></a-range-picker>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="门店类型"
                >
                  <cn-dict-select-tag v-decorator="['terminalType',validatorRules.terminalType]"
                                      :disabled="disableSubmit"
                                      :options="{value:'dictDataCode',label:'dictDataDesc'}" :triggerChange="true"
                                      dictCode="terminal_type" placeholder="请选择门店类型"
                                      :style="model.terminalType!=oldModel.terminalType&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"/>
                </a-form-item>
              </a-col>
              <!--门店等级-->
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="门店等级"
                >
                  <cn-dict-select-tag v-decorator="['terminalLevel',validatorRules.terminalLevel]"
                                      :disabled="disableSubmit"
                                      :options="{value:'dictDataCode',label:'dictDataDesc'}" :triggerChange="true"
                                      :style="model.terminalLevel!=oldModel.terminalLevel&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"
                                      dictCode="terminal_level" placeholder="请选择门店级别"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="所属组织"
                >
                  <j-tree-select
                    ref="selectRef"
                    v-decorator="['orgCode', validatorRules.orgCode]"
                    :disabled="disableSubmit"
                    data-type="org"
                    placeholder="选择组织"
                    :style="model.orgCode!=oldModel.orgCode&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"
                    @change="handleDepartCode"
                  />
                </a-form-item>
              </a-col>

              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="是否总店"
                >
                  <a-select
                    :disabled="disableSubmit"
                    v-decorator="['headOfficeStr',{}]"
                    placeholder="请选择"
                    :style="model.headOfficeStr!=oldModel.headOfficeStr&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"
                  >
                    <a-select-option value="是">
                      是
                    </a-select-option>
                    <a-select-option value="否">
                      否
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="面积"
                >
                  <a-input v-decorator="['acreage']" :disabled="disableSubmit" placeholder="请输入" :style="model.acreage!=oldModel.acreage&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="营业时间">
                  <a-time-picker v-decorator="[ 'businessStartDate']" :disabled="disableSubmit" format="HH:mm"
                                 valueFormat="HH:mm" :style="model.businessStartDate!=oldModel.businessStartDate&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"/>
                  <span> ~ </span>
                  <a-time-picker v-decorator="[ 'businessEndDate']" :disabled="disableSubmit" format="HH:mm"
                                 valueFormat="HH:mm" :style="model.businessEndDate!=oldModel.businessEndDate&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="店员数量"
                >
                  <a-input v-decorator="['clerkNum']" :disabled="disableSubmit" placeholder="请输入" style="width: 378px" :style="model.clerkNum!=oldModel.clerkNum&&model.businessFlag=='门店修改'&&title == '审批'?'color: red;':''"/>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="烟草许可证">
                  <j-image-upload v-decorator="['retailLicenceImg',validatorRules.retailLicenceImg]"
                                  :disabled="disableSubmit" class="avatar-uploader"
                                  text="上传"
                                  :style="model.retailLicenceImg!=oldModel.retailLicenceImg&&model.businessFlag=='门店修改'&&title == '审批'?'border: 1px solid red;':''"
                                  ></j-image-upload>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="门头照">
                  <j-image-upload :disabled="disableSubmit" class="avatar-uploader" text="上传"
                                  v-decorator="[ 'avatar', {}]"
                                  :style="model.avatar!=oldModel.avatar&&model.businessFlag=='门店修改'&&title == '审批'?'border: 1px solid red;':''"
                                  ></j-image-upload>
                </a-form-item>
              </a-col>
              <a-col :md="md" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="陈列照">
                  <j-upload v-decorator="['disPlayImgList',validatorRules.disPlayImgList]" :disabled="disableSubmit"
                            :number="3" :oldList="disPlayImgList"
                            :returnUrl="false"
                            accept=".png,.jpg,.jpeg" class="avatar-uploader"
                            fileType="image"
                            text="3张内"
                            :style="dispimg&&model.businessFlag=='门店修改'&&title == '审批'?'border: 1px solid red;':''"
                            @change="pdLogoChange"></j-upload>
                </a-form-item>
                <!--            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="陈列照">-->
                <!--              <j-image-upload v-decorator="[ 'disPlayImgList',validatorRules.disPlayImgList]" :disabled="disableSubmit" class="avatar-uploader"-->
                <!--                              text="上传"></j-image-upload>-->
                <!--            </a-form-item>-->
              </a-col>
              <!--          联系人-->
              <a-divider orientation="left" style="font-weight: 600;margin-top: 100px;">联系人电话</a-divider>
              <div v-for="(item,index) in forms" key="index">
                <a-form-model :label-col="labelCol" :rules="rules" :wrapper-col="wrapperCol">
                  <a-col :md="md==12?8:md" :sm="24">
                    <a-form-model-item
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      label="联系人"
                      prop="contacts"
                    >
                      <a-input v-model="item.contacts" :disabled="disableSubmit" placeholder="请输入联系人"
                      :style="model.businessFlag=='门店修改'&&oldModel.extendVos&&oldModel.extendVos.length&&oldModel.extendVos.length>=index+1&&item.contacts!=oldModel.extendVos[0].contacts?'color: red;':''"/>
                    </a-form-model-item>
                  </a-col>
                  <!--          联系电话-->
                  <a-col :md="md==12?8:md" :sm="24">
                    <a-form-model-item
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      label="联系电话"
                      prop="telephone"
                    >
                      <a-input v-model="item.telephone"
                               :disabled="disableSubmit" placeholder="请输入联系电话"
                               :style="model.businessFlag=='门店修改'&&oldModel.extendVos&&oldModel.extendVos.length&&oldModel.extendVos.length>=index+1&&item.telephone!=oldModel.extendVos[index].telephone?'color: red;':''"
                               />
                    </a-form-model-item>
                  </a-col>
                  <a-col :md="md==12?8:md" :sm="24">
                    <a-form-model-item
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      label="是否主号"
                      prop="isMainStr"
                    >
                      <a-select
                        v-model="item.isMainStr"
                        :disabled="disableSubmit"
                        placeholder="请选择"
                        :style="model.businessFlag=='门店修改'&&oldModel.extendVos&&oldModel.extendVos.length&&oldModel.extendVos.length>=index+1&&item.isMainStr!=oldModel.extendVos[index].isMainStr?'color: red;':''"
                      >
                        <a-select-option value="是">
                          是
                        </a-select-option>
                        <a-select-option value="否">
                          否
                        </a-select-option>
                      </a-select>
                    </a-form-model-item>
                  </a-col>
                </a-form-model>
                <a-button v-if="!disableSubmit" style="position: relative;right: -1150px;top: -38px;" type="primary"
                          @click="clickToadd($event,index)">{{ index == 0 ? '+' : '-' }}
                </a-button>
              </div>
            </a-row>
          </a-form>
        </a-col>
      </a-row>
    </a-spin>

    <!--      下方表单-->





    <a-divider orientation="left" style="font-weight: 600;margin-top: 0px;">审核流程</a-divider>
    <div style="width: 80%;margin: 24px auto">
      <!--      status="error"-->
      <a-steps :current="stepsIndex" size="small">
        <a-step v-for="(item,index) in approval" :key="index"
                :title="item.currentNodeDesc"
                :status="item.status"
                :subTitle="item.approvalTime"
        >
          <div slot="description">
            {{ item.approvalRealName }}
          </div>
          <div slot="description" v-if="item.remarks">
            意见:{{ item.remarks }}
          </div>
        </a-step>
      </a-steps>
    </div>
    <a-divider orientation="left" style="font-weight: 600;margin-top: 0px;">审批意见</a-divider>
    <a-form-item
    >
      <a-textarea v-model="remarks" :disabled="title!='审批'" allow-clear placeholder="请输入审批意见"
                  style="width:90%;margin-left:5%;min-height: 80px"/>
    </a-form-item>
    <proChose ref="prochoose" v-bind="modalProps" @okbro="okbropro"></proChose>
  </a-modal>
</template>
<script>
import ProduceList from '../modulesForndz/ProduceList'
import newCustperson from '../modulesForndz/newCustperson'
import { getAction, httpAction, postAction } from '@/api/manage'
import { pick } from 'lodash'
import moment from 'moment'
import JTreeSelect from '@/components/cn-form/JTreeSelect'
import JAreaLinkage from '@comp/cn-form/CnAreaLinkage'
import { isMobile, isPermit } from '@/utils/validate'
import UploadImage from '@/components/upload-image/UploadImage'
import JImageUpload from '@/components/cn-form/JImageUpload'
import Area from '@/components/utils/Area'
import proChose from '@comp/cn-components/ProChose'
import JUpload from '@/components/cn-form/JUpload'

export default {
  name: 'terminal-modal',
  components: {
    JTreeSelect,
    JAreaLinkage,
    UploadImage,
    JImageUpload,
    // CodeConfigModal,
    newCustperson,
    ProduceList,
    proChose,
    JUpload
  },
  data() {
    return {
      bigmd: 12,
      md: 24,
      approval: [],
      disPlayImgList: [], //陈列图片
      objs: [],
      title: '',
      dispimg:false, //判断照片
      isDisable: false, //提交按钮状态
      sendPro: false,
      ProductAdress: [],
      remarks: '',
      dataSurces2: [],
      formChoice: [],
      showCode: false,
      remembertext: '',
      dataSource: [],
      maninumd: [],
      arrcont: [],
      cycle: 1,
      forms: [{
        isMainStr: '请选择',
        contacts: '',
        telephone: '',
        isMain: ''
      }],
      dataSurces: [],
      // dataSurces3: [],
      manobjList: [0],
      selectedRowKeys6: [],
      selectionRows6: [],
      areaData: '',
      areaLinkage: '',
      visible: false,
      visible1: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      form1: this.$form.createForm(this),
      //formModel表单验证规则
      rules: {
        contacts: [
          { required: true, message: '', trigger: 'submit' }
        ],
        telephone: [
          { required: true, message: '', trigger: 'submit' }
        ],
        isMainStr: [
          { required: true, message: '', trigger: 'submit' }
        ]
      },
      validatorRules: {
        //烟草许可证号
        smokeLicenceNum: {
          rules: [
            { required: true, message: '', trigger: 'submit' }
          ]
        },
        //烟草许可证有效日期
        smokeLicenceDate: {
          rules: [
            { required: true, message: '' }
          ]
        },
        //零售许可证
        retailLicenceImg: {
          rules: [
            { required: true, message: '', trigger: 'submit' }
          ]
        },
        //陈列照
        disPlayImgList: {
          rules: [
            { required: true, message: [], trigger: 'submit' }
          ]
        },
        businessLicense: {
          rules: [
            { required: true, message: '请输入营业执照号', trigger: 'submit' }
          ]
        },
        terminalName: {
          rules: [
            { required: true, message: '请输入门店名称' }
          ]
        },
        warehouseName: {
          rules: [
            { required: true, message: '请选择所属仓库' }
          ]
        },
        address: {
          rules: [
            { required: true, message: '请输入详细地址' }
          ]
        },
        dictDataCode: {
          rules: [
            { required: true, message: '请选择渠道类型' }
          ]
        },
        terminalType: {
          rules: [
            { required: true, message: '请选择门店类型' }
          ]
        },
        terminalLevel: {
          rules: [
            { required: true, message: '请选择门店等级' }
          ]
        },
        store: {
          rules: [
            { required: true, message: '请选择是否总仓' }
          ]
        },
        contacts: {
          rules: [
            { required: true, message: '' }
          ]
        },
        parentRealName: {
          rules: [
            { required: true, message: '' }
          ]
        },
        orgCode: {
          rules: [
            { required: true, message: '请选择所属组织' }
          ]
        }
      },
      oldModel: {},
      addOrUpdateUrl: window._CONFIG['domianURL'] + '/approval/cnTerminalApproval/toExamine',

      list: window._CONFIG['domianURL'] + '/cnTerminalController/getCnTerminalByIdOrTerminalCode',

      getCustmen: window._CONFIG['domianURL'] + '/terminal/cnRTermPtPos/findCustCodeForUserPos',

      warehouse: window._CONFIG['domianURL'] + '/warehouse/cnWarehouse/findPageList',

      editTerminal: window._CONFIG['domianURL'] + '/terminal/cnRTermPtPos/findProductsByCustCode'
    }
  },
  created() {
    this.initAreaData()
    // console.log(this.areaData);
  },
  methods: {
    //陈列图片上传
    pdLogoChange(e) {
      this.disPlayImgList = []
      e.forEach(item => {
        this.disPlayImgList.push({
          url: item.url,
          name: item.name,
          uid: item.uid,
          status: 'done'
        })
      })
    },
    //添加请求参数，组织改变时，改变请求参数
    handleDepartCode(value, name) {
      console.log(name)
      this.model.departCode = ''
      this.model.departName = name
    },
    //关联客户返回数据
    okbropro(val, status, status2) {
      let objs = JSON.parse(JSON.stringify(val[0]))
      this.objs = objs
      this.form.setFieldsValue({
        custName: objs.custName,
        custCode: objs.custCode
      })
    },

    productSearch(status) {
      this.$refs.prochoose.rowKey = 'id'
      let formconfig = [
        {
          key: 'custCode',
          label: '客户编码'
        },
        {
          key: 'custName',
          label: '客户名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '客户编码',
            align: 'left',
            dataIndex: 'custCode',
            width: 120,
            ellipsis: true
          },
          {
            title: '客户名称',
            align: 'left',
            dataIndex: 'custName',
            width: 120,
            ellipsis: true
          }
        ],
        list: window._CONFIG['domianURL'] + '/customerController/getPageListElse',
        multiple: false,
        columW: 10
      }

      this.name = '用户'
      let dataSource = []
      if (this.form.getFieldValue('superiorUser')) {
        dataSource = [{
          userName: this.form.getFieldValue('superiorUser'),
          realName: this.form.getFieldValue('realsname')
        }]
      }
      console.log(dataSource)
      this.$refs.prochoose.edit(formconfig, tableconfig, 'superiorUser', 'realsname', dataSource)
    },
    handlePca(code) {
      this.model.provinceCode = code[0]
      this.model.cityCode = code[1]
      this.model.areaCode = code[2]
      this.model.province = this.areaData.getText(code).split('/')[0]
      this.model.city = this.areaData.getText(code).split('/')[1]
      this.model.area = this.areaData.getText(code).split('/')[2]
    },
    randomHexColor() { //随机生成十六进制颜色
      var hex = Math.floor(Math.random() * 16777216).toString(16) //生成ffffff以内16进制数
      while (hex.length < 6) { //while循环判断hex位数，少于6位前面加0凑够6位
        hex = '0' + hex
      }
      return '#' + hex //返回‘#'开头16进制颜色
    },
    add() {
      // this.edit({})
      this.form.resetFields()
      this.visible = true
    },
    async edit(record) {
      if (record.extendVos) {
        this.forms = record.extendVos
      } else {
        //新增时，防止联系人数据回显
        this.forms = [{
          isMainStr: '请选择',
          contacts: '',
          telephone: '',
          isMain: ''
        }]
      }
      if (this.title == '审批'&&record.businessFlag=='门店修改') {
        this.bigmd = 12
        this.md = 24
        let res = await getAction(this.list, { terminalCode: record.terminalCode })
        if (res.success) {
          let disPlayImgList = []
          let disPlayImgLists = res.result.disPlayImgList || []
          disPlayImgLists.forEach(item => {
            disPlayImgList.push({
              url: item.displayImg
            })
          })
          res.result.disPlayImgList = disPlayImgList||[]
          res.result.smokeLicenceDate = [res.result.smokeLicenceStartDate, res.result.smokeLicenceEndDate]
          res.result.areaLinkage = this.areaData.getAreaCodeByText(res.result.province + '/' + res.result.city + '/' + res.result.area) || ''
          this.$set(this, 'oldModel', res.result)
        }
        this.model.disPlayImgList=this.model.disPlayImgList||[]

      }else {
        this.bigmd = 24
        this.md = 12
      }
      this.form1.resetFields()
      this.ProductAdress = []
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.model.smokeLicenceDate = [this.model.smokeLicenceStartDate, this.model.smokeLicenceEndDate]
      let disPlayImgList = []
      let disPlayImgLists = this.model.disPlayImgList || []
      disPlayImgLists.forEach(item => {
        disPlayImgList.push({
          url: item.displayImg
        })
      })
      this.model.disPlayImgList = disPlayImgList||[]
      this.oldModel.disPlayImgList=this.oldModel.disPlayImgList||[]
      console.log(this.model.disPlayImgList,this.oldModel.disPlayImgList)
      if(this.model.disPlayImgList.length==this.oldModel.disPlayImgList.length){
        let index=this.model.disPlayImgList.length
        if(index==3){
          if(this.model.disPlayImgList[0].url==this.oldModel.disPlayImgList[0].url&&this.model.disPlayImgList[1].url==this.oldModel.disPlayImgList[1].url&&this.model.disPlayImgList[2].url==this.oldModel.disPlayImgList[2].url){
            this.dispimg=false
          }
        }else if(index==2){
          if(this.model.disPlayImgList[0].url==this.oldModel.disPlayImgList[0].url&&this.model.disPlayImgList[1].url==this.oldModel.disPlayImgList[1].url){
            this.dispimg=false
          }
        }else if(index==1){
          if(this.model.disPlayImgList[0].url==this.oldModel.disPlayImgList[0].url){
            this.dispimg=false
          }
        }else if(index==0){
            this.dispimg=false
        }else{
          this.dispimg=true
        }
      }else{
        this.dispimg=true
      }
      this.dataSurces2 = record.tptposVos || []
      let pca = this.model.province + '/' + this.model.city + '/' + this.model.area
      this.areaLinkage = this.areaData.getAreaCodeByText(pca) || ''
      this.visible = true
      this.$nextTick(() => {
        setTimeout(() => {
          this.form.setFieldsValue({
            orgName: '请选择'
          })
          this.form.setFieldsValue(pick(this.model, Object.keys(this.model)))
          //时间格式化
          this.form.setFieldsValue({ punchTime: this.model.punchTime ? moment(this.model.punchTime, 'YYYY-MM-DD HH:mm:ss') : null })
          this.form.setFieldsValue({ birthday: this.model.birthday ? moment(this.model.birthday) : null })
        }, 200)
      })
      this.getApproval()
      if (typeof record.createName == 'undefined') {
        this.sendPro = false
      } else {
        let Address = []
        if (this.model.addresses) {
          this.model.addresses.forEach(item => {
            Address.push(item)
          })
        }
        this.ProductAdress = Address
        this.sendPro = true
      }
    },

    async getApproval() {
      if (this.model.id) {
        let res = await postAction('/approval/cnApprovalLog/findNodeLogList', {
          businessFlag: this.model.businessFlag,
          businessId: this.model.id
        })
        if (res.success) {
          this.approval = res.result.map((item, index) => {
            if (item.approvalStatus == 4) {
              item.status = 'error'
            } else if (item.approvalTime) {
              item.status = 'finish'
            } else if (!item.approvalTime && res.result[index - 1].approvalTime) {
              item.status = 'process'
            } else {
              item.status = 'wait'
            }
            return item
          })
        } else {
          this.$message.error(res.message)
        }
      }
    },

    close() {
      this.$emit('close')
      this.visible = false
      this.disPlayImgList = []
      this.approval = []
      this.remarks = ''
    },
    onSelectChange6(selectedRowKeys, selectionRows) {
      this.selectedRowKeys6 = selectedRowKeys
      this.selectionRows6 = selectionRows
    },

    handleOk1() {
      this.visible1 = false
      // this.model.warehouseName =
      this.form.setFieldsValue({
        warehouseName: this.selectionRows6[0].warehouseName
      })
      this.model.warehouseCode = this.selectionRows6[0].warehouseCode

    },
    handleOk(status) {
      let formData = {
        approvalStatus: status,
        remarks: this.remarks,
        id: this.model.id,
        terminalCode: this.model.terminalCode
      }
      this.confirmLoading = true
      let that = this
      httpAction(this.addOrUpdateUrl, formData, 'post').then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
          that.close()
        } else {
          that.$message.warning(res.message)
        }
      }).finally(() => {
        that.confirmLoading = false
      })
    },
    handleCancel1() {
      this.visible1 = !this.visible1
    },
    handleCancel() {
      this.close()
    },
    initAreaData() {
      if (!this.areaData) {
        this.areaData = new Area()
      }
    },
    clickToadd(val, index) {
      this.dataSurces.length == 0

      console.log(val)
      if (val.target.innerText == '+') {
        this.forms.push({
          isMainStr: '请选择',
          contacts: '',
          telephone: ''
        })
      } else {
        this.forms.splice(index, 1)
      }
      const { count, manobjList, dataSurces, forms } = this
      let dc = {}
      if (dataSurces.length == 0) {
        dataSurces.push({
          ...forms
        })
      } else {
        dataSurces.forEach((item, index) => {
          dc = Object.assign(item, forms)
          item = dc
        })
      }
      console.log(dataSurces)
      this.dataSurces2 = Array.from(new Set(this.dataSurces2.concat(dataSurces)))
      this.dataSurces = []
      // this.forms = [{
      //   isMainStr: '请选择',
      //   contacts: '',
      //   telephone:'',
      // }]
    },
    onDelete(key) {
      const dataSurces = [...this.dataSurces]
      this.dataSurces = dataSurces.filter(item => item !== key)
    },
    onDeleteee(key) {
      const dataSurces2 = [...this.dataSurces2]
      this.dataSurces2 = dataSurces2.filter(item => item !== key)
    },
    // 收货地址删除
    onDeletes(key) {
      const dataSurces = [...this.ProductAdress]
      this.ProductAdress = dataSurces.filter(item => item !== key)
    },

    handleSelectCode() {
      this.$refs.CodeConfigModal.showModal(this.userTypeTp)
    },

    custpersonOk(ob) {
      if (ob !== null && ob !== {}) {
        // this.forms.contacts = ob.contacts
        // this.forms.ogName = ob.ogName
        // this.forms.ogCode = ob.ogCode
        // this.forms.userName = ob.userName
        // this.forms.posCode = ob.posCode
        // this.forms.posName = ob.posName
        this.$set(this.forms, 'contacts', ob.contacts)
        this.$set(this.forms, 'ogName', ob.ogName)
        this.$set(this.forms, 'telephone', ob.telephone)
        this.$set(this.forms, 'ogCode', ob.ogCode)
        this.$set(this.forms, 'userName', ob.userName)
        this.$set(this.forms, 'posCode', ob.posCode)
        this.$set(this.forms, 'posName', ob.posName)
        return
      }
      this.$message.error('获取客户数据失败')
    },
    // 点击业务员响应{事件

    // handletoSelectPerson() {
    //   this.$refs.newCustperson.showModal(this.forms.custCode)
    // },
    // // 添加商品的数据回返
    productscontact(value) {
      console.log(value)
      this.dataSurces = value
      // let length = this.dataSurces.length
      // let a = []
      // value.forEach(item => {
      //   a.push(item)
      // })
      // this.dataSurces.splice(0, length, ...a)
    }
  }
}
</script>

<style scoped>
.gonghuoxinxi {
  width: 100%;
  border-bottom: 1px dashed black;
  margin: 10px 0;
  padding: 15px 5px;
  display: flex;
  flex-direction: column;
}
</style>
